package cn.xugongwei.microserviceprovide8442.service.impl;

import cn.xugongwei.microservicecommon.dao.UserDao;
import cn.xugongwei.microservicecommon.entity.UserEntity;
import cn.xugongwei.microserviceprovide8442.service.UserService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author xugongwei (isxugongwei(a)gmail.com)
 * @version 1.0
 * @date 2019/4/10 12:00
 */
@Service("UserService")
public class UserServiceImpl implements UserService {

    @Override
    public List<UserEntity> listUser() {
        System.out.println("microservice-provide-8442");

        List<UserEntity> list = UserDao.getList();
        if (list.isEmpty()) {
            throw new RuntimeException("暂无记录，请稍后再试");
        }
        return list;
    }

    @Override
    public UserEntity getUserById(Integer id) {
        System.out.println("microservice-provide-8442");

        UserEntity user = UserDao.getUserById(id);
        if (user == null) {
            throw new RuntimeException("ID为" + id + "的用户不存在");
        }
        return user;
    }
}
